package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;

/*
 ID:	liluyan1
 LANG:	JAVA
 TASK:	pprime
 */
public class pprime {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("pprime.in"));
		ArrayList<Integer> res = new pprime().solve(f);
		Collections.sort(res);
		
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"pprime.out")));
		for (int i : res) out.println(i);
		out.close();
		System.exit(0);
	}
	
	private int MAX = 10000;
	private HashSet<Integer> primes = new HashSet<Integer>();
	private ArrayList<Integer> res;
	private int low, high;
	
	private ArrayList<Integer> solve(BufferedReader f) throws IOException {
		res = new ArrayList<Integer>();
		int[] a = read(f, 2);
		low = a[0];
		high = a[1];
		sieve(high);
		
		for (int i=1; i<9; i++) {
			if (i%2 == 0) {
				even(i, 0, 10);
			}
			else {
				odd(i, 0);
			}
		}
		
		return res;
	}
	
	private void even(int i, int value, int base) {
		if (i == 0) {
			if (isPrime(value)) res.add(value);
			return;
		}
		for (int j=0; j<10; j++) {
			if (i==2 && j==0) continue;
			even(i-2, j*base + value*10 + j, base*100);
		}
	}
	
	private void odd(int i, int value) {
		for (int j=0; j<10; j++) {
			if (i==1 && j==0) continue;
			even(i-1, j, 100);
		}
	}
	
	private void sieve(int N) {
		int M = Math.min(N, MAX);
		boolean[] np = new boolean[M + 1];
		for (int i=2; i*i<=M; i++) {
			if (np[i]) {
				continue;
			}
			for (int j=i*2; j<=M; j+=i) {
				np[j] = true;
			}
		}
		for (int i=2; i<=M; i++) if (!np[i]) primes.add(i);
	}
	
	private boolean isPrime(int a) {
		if (a < low || a > high) return false;
		if (a < MAX) return primes.contains(a);
		for (int i : primes) {
			if (a % i == 0) return false;
		}
		return true;
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
